package com.example.learnspringboot07principle.listener;

import org.springframework.boot.ConfigurableBootstrapContext;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.SpringApplicationRunListener;
import org.springframework.context.ConfigurableApplicationContext;
import org.springframework.core.env.ConfigurableEnvironment;

import java.time.Duration;

public class HelloSpringApplicationRunListener implements SpringApplicationRunListener {

    public HelloSpringApplicationRunListener(SpringApplication application, String[] args) {
//        System.out.println("HelloSpringApplicationListener 构造函数");
    }

    @Override
    public void starting(ConfigurableBootstrapContext bootstrapContext) {
//        SpringApplicationRunListener.super.starting(bootstrapContext);
        System.out.println("HelloSpringApplicationListener starting 方法");
    }

    @Override
    public void environmentPrepared(ConfigurableBootstrapContext bootstrapContext, ConfigurableEnvironment environment) {
//        SpringApplicationRunListener.super.environmentPrepared(bootstrapContext, environment);
        Object o = environment.getSystemProperties().get("os.name");
        System.out.println("HelloSpringApplicationListener environmentPrepared 方法 "+o);

    }

    @Override
    public void contextPrepared(ConfigurableApplicationContext context) {
//        SpringApplicationRunListener.super.contextPrepared(context);
        System.out.println("HelloSpringApplicationListener contextPrepared 方法");

    }

    @Override
    public void contextLoaded(ConfigurableApplicationContext context) {
//        SpringApplicationRunListener.super.contextLoaded(context);
        System.out.println("HelloSpringApplicationListener contextLoaded 方法");

    }

    @Override
    public void started(ConfigurableApplicationContext context, Duration timeTaken) {
//        SpringApplicationRunListener.super.started(context, timeTaken);
        System.out.println("HelloSpringApplicationListener started 方法");

    }

    @Override
    public void ready(ConfigurableApplicationContext context, Duration timeTaken) {
//        SpringApplicationRunListener.super.ready(context, timeTaken);
        System.out.println("HelloSpringApplicationListener ready 方法");

    }

    @Override
    public void failed(ConfigurableApplicationContext context, Throwable exception) {
        SpringApplicationRunListener.super.failed(context, exception);
        System.out.println("HelloSpringApplicationListener failed 方法");

    }
}
